import { request } from '@/utils/request'
import type { ApiResponse } from '@/utils/request'

/**
 * 教室信息查询参数
 */
export interface ClassroomQuery {
  schoolId?: number
  classroomCode?: string
  classroomName?: string
  building?: string
  classroomType?: string
  status?: string
  isMultimedia?: boolean
  isComputerRoom?: boolean
  isLab?: boolean
  pageNum: number
  pageSize: number
}

/**
 * 教室信息表单数据
 */
export interface ClassroomForm {
  id?: number
  schoolId: number
  schoolName?: string
  classroomCode: string
  classroomName: string
  building?: string
  floor?: number
  roomNumber?: string
  classroomType?: string
  capacity?: number
  isMultimedia?: boolean
  isComputerRoom?: boolean
  isLab?: boolean
  equipment?: string
  status?: string
  notes?: string
}

/**
 * 教室信息详情
 */
export interface ClassroomInfo extends ClassroomForm {
  createdTime?: string
  updatedTime?: string
}

/**
 * 教室分页结果接口
 */
export interface ClassroomPageResult {
  records: ClassroomInfo[]
  total: number
  size: number
  current: number
  pages: number
}

/**
 * 获取教室列表
 * @param query 查询参数
 * @returns 分页结果
 */
export function listClassroom(query: ClassroomQuery) {
  return request.post<ApiResponse<ClassroomPageResult>>('/api/school/classroom/list', query)
}

/**
 * 获取教室详情
 * @param id 教室ID
 * @returns 教室详情
 */
export function getClassroom(id: number) {
  return request.get<ApiResponse<ClassroomInfo>>(`/api/school/classroom/${id}`)
}

/**
 * 新增教室
 * @param data 教室数据
 * @returns 新增结果
 */
export function addClassroom(data: ClassroomForm) {
  return request.post<ApiResponse<boolean>>('/api/school/classroom', data)
}

/**
 * 修改教室
 * @param data 教室数据
 * @returns 修改结果
 */
export function updateClassroom(data: ClassroomForm) {
  return request.put<ApiResponse<boolean>>('/api/school/classroom', data)
}

/**
 * 删除教室
 * @param id 教室ID
 * @returns 删除结果
 */
export function deleteClassroom(id: number) {
  return request.delete<ApiResponse<boolean>>(`/api/school/classroom/${id}`)
}

/**
 * 批量删除教室
 * @param ids 教室ID数组
 * @returns 批量删除结果
 */
export function batchDeleteClassroom(ids: number[]) {
  return request.delete<ApiResponse<boolean>>('/api/school/classroom/batch', ids)
}

/**
 * 获取教室状态选项
 * @returns 教室状态选项
 */
export function getClassroomStatusOptions() {
  return [
    {
      value: 'AVAILABLE',
      label: '可用'
    },
    {
      value: 'MAINTENANCE',
      label: '维修中'
    },
    {
      value: 'DISABLED',
      label: '停用'
    }
  ]
}

/**
 * 获取教室类型选项
 * @returns 教室类型选项
 */
export function getClassroomTypeOptions() {
  return [
    {
      value: '普通教室',
      label: '普通教室'
    },
    {
      value: '多媒体教室',
      label: '多媒体教室'
    },
    {
      value: '实验室',
      label: '实验室'
    },
    {
      value: '报告厅',
      label: '报告厅'
    }
  ]
} 